package com.kuangjia.student_ems.entity;

import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.TableField;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.LocalDateTime;

@Entity
@Table(name = "attendances")
@Data
@NoArgsConstructor
@AllArgsConstructor
@TableName("attendances")
public class Attendance {
    
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @TableId(value = "id", type = com.baomidou.mybatisplus.annotation.IdType.AUTO)
    private Long id;
    
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "user_id", nullable = false)
    @TableField(exist = false)
    private User user;
    
    @TableField("user_id")
    @Column(name = "user_id", insertable = false, updatable = false)
    private Long userId;
    
    @Column(nullable = false)
    private LocalDate date;
    
    private LocalDateTime checkInTime;
    
    private LocalDateTime checkOutTime;
    
    @Enumerated(EnumType.STRING)
    @Column(nullable = false)
    private AttendanceStatus status;
    
    private String remark;
    
    @CreationTimestamp
    private LocalDateTime createTime;
    
    // 签到位置相关字段
    @Column(precision = 10, scale = 8)
    private BigDecimal checkInLatitude; // 签到纬度
    
    @Column(precision = 11, scale = 8)
    private BigDecimal checkInLongitude; // 签到经度
    
    private String checkInLocation; // 签到位置描述
    
    private String checkInAddress; // 签到详细地址
    
    @Column(precision = 5, scale = 2)
    private BigDecimal checkInAccuracy; // 签到位置精度(米)
    
    @Enumerated(EnumType.STRING)
    private LocationSource checkInLocationSource; // 签到位置来源
    
    private LocalDateTime checkInLocationTime; // 签到位置获取时间
    
    // 签退位置相关字段
    @Column(precision = 10, scale = 8)
    private BigDecimal checkOutLatitude; // 签退纬度
    
    @Column(precision = 11, scale = 8)
    private BigDecimal checkOutLongitude; // 签退经度
    
    private String checkOutLocation; // 签退位置描述
    
    private String checkOutAddress; // 签退详细地址
    
    @Column(precision = 5, scale = 2)
    private BigDecimal checkOutAccuracy; // 签退位置精度(米)
    
    @Enumerated(EnumType.STRING)
    private LocationSource checkOutLocationSource; // 签退位置来源
    
    private LocalDateTime checkOutLocationTime; // 签退位置获取时间
    
    // 位置验证字段
    private Boolean locationVerified = false; // 位置是否已验证
    
    private String locationVerificationNote; // 位置验证备注
    
    public enum AttendanceStatus {
        NORMAL,      // 正常
        LATE,        // 迟到
        EARLY_LEAVE, // 早退
        ABSENT,      // 缺勤
        LEAVE        // 请假
    }
    
    public enum LocationSource {
        GPS,        // GPS定位
        NETWORK,    // 网络定位
        MANUAL      // 手动输入
    }
} 